//
//  LoginView.m
//  JunZeWristband
//
//  Created by Kendama on 2017/8/16.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "LoginView.h"

@implementation LoginView

- (instancetype)init
{
    self = [super init];
    if (self)
    {
        [self masLayoutSubview];
        
    }
    return self;
}

#pragma mark -- 懒加载
- (UIImageView *)bgImageView
{
    if(!_bgImageView)
    {
        UIView *superView = self;
        _bgImageView = [[UIImageView alloc]init];
        _bgImageView.image = [UIImage imageNamed:@"bg_login"];
        [superView addSubview:_bgImageView];
    }
    return _bgImageView;
}

- (UIImageView *)logoImageView
{
    if(!_logoImageView)
    {
        UIView *superView = self;
        _logoImageView = [[UIImageView alloc]init];
        _logoImageView.image = [UIImage imageNamed:@"logo"];
        [superView addSubview:_logoImageView];
    }
    return _logoImageView;
}


- (UIView *)centerView
{
    if(!_centerView)
    {
        UIView *superView = self;
        _centerView = [[UIView alloc]init];
        _centerView.backgroundColor = [UIColor whiteColor];
        _centerView.layer.cornerRadius = 5;
        [superView addSubview:_centerView];
    }
    return _centerView;
}

- (PhoneTextFieldView *)phoneView
{
    if(!_phoneView)
    {
        UIView *superView = self.centerView;
        _phoneView = [[PhoneTextFieldView alloc]init];
        _phoneView.iconImageView.image = [UIImage imageNamed:@"icon_phone2"];
        _phoneView.phoneTextField.placeholder = MyNSLocalizedString(@"请输入手机号");
        _phoneView.phoneTextField.keyboardType = UIKeyboardTypePhonePad;
        [superView addSubview:_phoneView];
    }
    return _phoneView;
}


- (PasswordTextFieldView *)passwordView
{
    if(!_passwordView)
    {
        UIView *superView = self.centerView;
        _passwordView = [[PasswordTextFieldView alloc]init];
        _passwordView.iconImageView.image = [UIImage imageNamed:@"icon_code"];
        _passwordView.passwordTextField.placeholder = MyNSLocalizedString(@"请输入密码");
        [superView addSubview:_passwordView];
    }
    return _passwordView;
}

- (UIButton *)registerButton
{
    if(!_registerButton)
    {
        UIView *superView = self;
        _registerButton = [[UIButton alloc]init];
        [superView addSubview:_registerButton];
        [_registerButton setTitle:MyNSLocalizedString(@"立即注册") forState:UIControlStateNormal];
        [_registerButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
        [_registerButton setTitleColor:[UIColor colorWithHexString:@"979797"] forState:UIControlStateNormal];

    }
    return _registerButton;
}
- (UIButton *)forgetButton
{
    if(!_forgetButton)
    {
        UIView *superView = self;
        _forgetButton = [[UIButton alloc]init];
        [superView addSubview:_forgetButton];
        [_forgetButton setTitle:MyNSLocalizedString(@"忘记密码?") forState:UIControlStateNormal];
        [_forgetButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
        [_forgetButton setTitleColor:[UIColor colorWithHexString:@"979797"] forState:UIControlStateNormal];

    }
    return _forgetButton;
}

- (UIButton *)loginButton
{
    if(!_loginButton)
    {
        UIView *superView = self;
        _loginButton = [[UIButton alloc]init];
        [superView addSubview:_loginButton];
        [_loginButton setTitle:MyNSLocalizedString(@"登录") forState:UIControlStateNormal];
        [_loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_loginButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
        [_loginButton setBackgroundImage:[UIImage imageNamed:@"but_login"] forState:UIControlStateNormal];
    }
    return _loginButton;
}
- (UIButton *)qqButton
{
    if(!_qqButton)
    {
        UIView *superView = self;
        _qqButton = [[UIButton alloc]init];
        [superView addSubview:_qqButton];
        [_qqButton setBackgroundImage:[UIImage imageNamed:@"icon_QQ"] forState:UIControlStateNormal];
    }
    return _qqButton;
}
- (UIButton *)wechatButton
{
    if(!_wechatButton)
    {
        UIView *superView = self;
        _wechatButton = [[UIButton alloc]init];
        [superView addSubview:_wechatButton];
        [_wechatButton setBackgroundImage:[UIImage imageNamed:@"icon_WeChat"] forState:UIControlStateNormal];
    }
    return _wechatButton;
}
- (UIButton *)weiboButton
{
    if(!_weiboButton)
    {
        UIView *superView = self;
        _weiboButton = [[UIButton alloc]init];
        [superView addSubview:_weiboButton];
        [_weiboButton setBackgroundImage:[UIImage imageNamed:@"icon_micro"] forState:UIControlStateNormal];
    }
    return _weiboButton;
}

//- (UIImageView *)thirdLoginImageView
//{
//    if(!_thirdLoginImageView)
//    {
//        UIView *superView = self;
//        _thirdLoginImageView = [[UIImageView alloc]init];
//        [superView addSubview:_thirdLoginImageView];
//        _thirdLoginImageView.image = [UIImage imageNamed:@"third_login"];
//    }
//    return _thirdLoginImageView;
//}
- (UILabel *)thirdLoginLabel
{
    if(!_thirdLoginLabel)
    {
        UIView *superView = self;
        _thirdLoginLabel = [[UILabel alloc]init];
        [superView addSubview:_thirdLoginLabel];
        [_thirdLoginLabel setFont:fontWithSize(15)];
        [_thirdLoginLabel setTextColor:[UIColor whiteColor]];
        _thirdLoginLabel.textAlignment = NSTextAlignmentCenter;
        _thirdLoginLabel.text = [NSString stringWithFormat:@"---------------%@---------------",MyNSLocalizedString(@"第三方登录")];
    }
    return _thirdLoginLabel;
}


#pragma -- 初始化
- (void)masLayoutSubview
{
    __weak UIView *superView = self;
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(superView);
    }];
    
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top).with.offset(px1920Height(264));
        make.left.mas_equalTo(superView.mas_left).with.offset(px1080Width(292));
    }];
    
    [self.centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView).with.offset(px1920Height(662));
        make.left.mas_equalTo(superView.mas_left).with.offset(px1080Width(55));
        make.right.mas_equalTo(superView.mas_right).with.offset(px1080Width(-55));
        make.height.mas_equalTo(px1920Height(479));
    }];
    
    [self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.centerView.mas_top);
        make.left.mas_equalTo(self.centerView.mas_left);
        make.right.mas_equalTo(self.centerView.mas_right);
        make.height.mas_equalTo(px1920Height(165));
    }];
    
    [self.passwordView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.phoneView.mas_bottom);
        make.left.mas_equalTo(self.centerView.mas_left);
        make.right.mas_equalTo(self.centerView.mas_right);
        make.height.mas_equalTo(px1920Height(165));
    }];
    
    [self.registerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.passwordView.mas_bottom).with.offset(px1920Height(10));
        make.left.mas_equalTo(self.centerView.mas_left).with.offset(px1080Width(50));
    }];
    
    [self.forgetButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.passwordView.mas_bottom).with.offset(px1920Height(10));
        make.right.mas_equalTo(self.centerView.mas_right).with.offset(px1080Width(-50));
    }];
    
    [self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(superView.mas_centerX);
        make.top.mas_equalTo(self.centerView.mas_bottom).with.offset(px1920Height(90));
    }];
    
    [self.thirdLoginLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.loginButton.mas_bottom).with.offset(px1920Height(191));
        make.left.and.right.mas_equalTo(superView);
    }];
    
    CGFloat padding = px1080Width(126);
    NSMutableArray *views = [NSMutableArray array];
    [views addObjectsFromArray:@[self.qqButton,self.wechatButton,self.weiboButton]];
    [views mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:px1080Width(160) leadSpacing:padding tailSpacing:padding];
    [views mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.thirdLoginLabel.mas_bottom).with.offset(px1920Height(70));
        UIView *blueView = (UIView *)views[0];
        make.height.mas_equalTo(blueView.mas_width);
    }];
}

@end
